<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>弹框</title>
    <style>
        #simpleModal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            height: 100%;
            width: 100%;
            overflow: hidden;
            background-color: rgba(0, 0, 0, 0.5);
            color: #333;
        }

        #simpleModal .modal-content {
            background-color: #f4f4f4;
            margin: 15% auto;
            width: 40%;
            box-shadow: 0 5px 8px 0 rgba(0, 0, 0, 0.2), 0 7px 20px 0 rgba(0, 0, 0, 0.2);
            animation-name: modalopen;
            animation-duration: 1s;
            font-size: 16px;
        }

        #simpleModal .title {
            margin: 0;
            color: #000000d9;
            font-weight: 600;
            font-size: 18px;
            line-height: 22px;
            word-wrap: break-word;
        }

        #simpleModal .modal-header {
            padding: 4px 24px;
            color: #000000d9;
            background: #EDEDED;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        #simpleModal .closeBtn {
            color: #333;
            float: right;
            font-size: 30px;
            transition: all 0.3s;
        }

        #simpleModal .closeBtn:hover,
        .closeBtn:focus {
            color: #333;
            text-decoration: none;
            cursor: pointer;
        }

        #simpleModal .modal-body {
            padding: 10px 50px;
        }

        #simpleModal .date {
            display: flex;
            justify-content: flex-end;
            padding-right: 10px;
        }

        #simpleModal .modal-footer {
            padding: 15px;
            text-align: center;
            cursor: pointer;
        }

        #simpleModal .sureBtn {
            background-color: #1E9FFF;
            color: #fff;
            padding: 6px 15px;
            border-radius: 3px;
            font-size: 15px;
            display: inline-block;
        }

        @keyframes modalopen {
            from {
                opacity: 0
            }

            to {
                opacity: 1
            }
        }
    </style>
</head>

<body>
    <script>
        var content = `
                        <div class="modal-content">
                            <div class="modal-header">
                                <div class="title">通知</div>
                                <span class="closeBtn">&times;</span>
                            </div>
                            <div class="modal-body">
                                <p>
                                    各位用户：<br/>
                                    由于我单位所在区域于2021年9月24日（周五）18:00至9月25日（周六）09:00停电，届时将暂停提供电子政务外网天地图服务。带来不便，敬请谅解。
                                    <span class="date">2021年9月22日</span>
                                </p>
                            </div>
                            <div class="modal-footer">
                                <span class="sureBtn" id="sure">知道了</span>
                            </div>
                        </div>`;
        var tipContainer = document.createElement('div');
        tipContainer.className = 'modal';
        tipContainer.id = 'simpleModal';
        tipContainer.innerHTML = content;
        document.body.appendChild(tipContainer);
        // 获取弹窗元素
        var modal = document.getElementById("simpleModal");

        // 获取关闭弹窗按钮元素
        var closeBtn = document.getElementsByClassName("closeBtn")[0];

        // 监听关闭弹窗事件
        closeBtn.addEventListener("click", closeModal);

        document.getElementById('sure').addEventListener("click", closeModal);

        // 监听window关闭弹窗事件
        window.addEventListener("click", outsideClick);

        // 弹窗事件
        function openModal() {
            modal.style.display = "block";
        }

        // 关闭弹框事件
        function closeModal() {
            modal.style.display = "none";
            document.body.removeChild('tipContainer')
        }

        // outsideClick
        function outsideClick(e) {
            if (e.target == modal) {
                modal.style.display = "none";
            }
        }

        openModal();
    </script>
</body>

</html>